package algotithm.leetcode.greey.test12;

/**
 * @author zhouyanxiang
 * @Date 2021-04-2021/4/19-22:43
 * @Title 12. 整数转罗马数字
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int num = 3;
        String s = solution.intToRoman(num);
        System.out.println(s);
    }

    public String intToRoman(int num) {
        int[] a = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
        String[] arr = {"M", "CM","D","CD","C","XC","L", "XL","X","IX","V", "IV","I"};
        //"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"
        int index = 0;
        StringBuilder sb = new StringBuilder();
        while (index < arr.length) {
            while (num >= a[index]) {
                sb.append(arr[index]);
                num -= a[index];
            }
            index++;
        }
        return sb.toString();
    }
}